package ajax;

import javax.security.auth.login.LoginException;



public enum MessagesAjaxActions {
	
	LOGIN_SEARCH {
		@Override
		public void doAction(MessagesAjaxBean bean) throws LoginException  {
			String login = bean.getStringFromParam("login");
			if( login == null || login.isEmpty()){
				throw new LoginException("Error");
			}
			String message = null ;
			if(login.equals("login")){
				message = "used";
			}else{
				message = "free";
			}
			bean.addPropertyToRes("userlogin",message);
		}
	};
	
	public static MessagesAjaxActions getActionFromString(String str) throws LoginException{
		if(str != null && !str.isEmpty() ){
			if(str.equals("login_search")){
				return LOGIN_SEARCH;
			}
		}
		throw new LoginException("Error");
	}
	public abstract void doAction(MessagesAjaxBean bean) throws LoginException ;
}
